import { request } from 'umi';

// 登录验证
export async function User_Login(phoneNumber: string, password: string) {
  return request(`/api/user/loginStatus`, {
    method: 'get',
    params: {
      user_telephone: phoneNumber,
      user_password: password,
    },
  });
}

// 登录成功返回用户信息
export async function User_Login_Next(phoneNumber: string) {
  return request(`/api/user/loginUser`, {
    method: 'get',
    params: {
      user_telephone: phoneNumber,
    },
  });
}

// 用户注册
export async function User_Register(
  userName: string,
  password: string,
  phoneNumber: string,
  address: string,
  email: string,
) {
  return request(`/api/user/register`, {
    method: 'post',
    params: {
      user_name: userName,
      user_password: password,
      user_telephone: phoneNumber,
      user_address: address,
      user_mailbox: email,
    },
  });
}

// 发布书籍
export async function Book_Publish(
  bookName: string,
  author: string,
  publisher: string,
  type: string,
  price: string,
  degree: string,
  description: string,
  image: string,
  sellerId: string,
) {
  return request(`/api/book/postBook`, {
    method: 'post',
    params: {
      book_name: bookName,
      book_author: author,
      book_publisher: publisher,
      book_type: type,
      book_price: price,
      book_degree: degree,
      book_description: description,
      seller_id: sellerId,
    },
    data: {
      book_image: image,
    },
  });
}

// 获取首页默认书籍列表
export async function Get_All_Book() {
  return request(`/api/book/selectBookByInfo`, {
    method: 'get',
  });
}

// 根据用户id获得用户信息
export async function Get_User_ById(userId: string) {
  return request(`/api/user/getUser`, {
    method: 'get',
    params: {
      user_id: userId,
    },
  });
}

// 根据书籍id获得书籍信息
export async function Get_Book_ById(bookId: string) {
  return request(`/api/book/selectBookById`, {
    method: 'get',
    params: {
      book_id: bookId,
    },
  });
}

export async function Get_Book_ByInfo(
  keyWord: string,
  type: string,
  order: string,
) {
  return request(`/api/book/selectBookByInfo`, {
    method: 'get',
    params: {
      book_name: keyWord,
      book_type: type,
      order_type: order,
    },
  });
}

export async function Get_My_Book(user_id: string, selectType: string) {
  return request(`/api/book/selectBookByUser`, {
    method: 'get',
    params: {
      user_id: user_id,
      select_type: selectType,
    },
  });
}

export async function Buy_Book(book_id: string, buyer_id: string) {
  return request(`/api/book/tradeBook`, {
    method: 'post',
    params: {
      book_id: book_id,
      buyer_id: buyer_id,
    },
  });
}

export async function Get_Bought_Book(book_id: string) {
  return request(`/api/book/accomplishTrade`, {
    method: 'post',
    params: {
      book_id: book_id,
    },
  });
}
